<template>
	<view class="content">
	    <!-- 客户++++++++++++ -->
		<view style="background: #fff;padding: 20px 0px;" v-if="iskehu">
			<view class="line_title" style="color: #666;" v-if="info.is_finish==-1">
				已逾期（元）
			</view>
			<view class="line_title" style="color: #666;" v-if="info.is_finish!=-1&&info.is_finish!=1">
				剩余应还（元）
			</view>
			<view class="line_title" style="color: #666;" v-if="info.is_finish==1">
			    贷款已还清（元）
			</view>
			<view class="big-number" style="color: #1e99ff;text-align: center;" v-if="info.is_finish!=1">{{info.elsecapital}}</view>
			<view class="big-number" style="color: #1e99ff;text-align: center;"  v-if="info.is_finish==1">{{info.paymoney}}</view>
			<view class="line_title" style="color: #666">贷款总额{{info.capital}}、已还{{info.paymoney}}、利息{{info.investment}}</view>
			<button class="big_button button_shadow" style="margin-top: 20rpx;" @tap="backloan()">
				立即还款
			</button>
		</view>
		<!-- 业务++++++++++++ -->
		<view style="background: #fff;padding: 20px 0px;" v-if="isyewu">
			<view class="line_title" style="color: #666;">
				贷款金额
			</view>
			<view class="big-number" style="color: #1e99ff;text-align: center;">{{info.capital}}</view>
		</view>
		<view class="mokuai" style="margin: 20rpx;padding: 20rpx;">
			<view class="info_title">
				贷款明细
			</view>
			<view class="clear shenhe-text">
				<text class="left">申请时间 </text>
				<text class="right">{{info.addtime}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">通过时间 </text>
				<text class="right">{{info.checktime3}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">贷款金额 </text>
				<text class="right" >{{info.capital}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">还款期限 </text>
				<text class="right" >{{info.tongguo}}至{{info.endtime}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">查看合同</text>				
			</view>
			<view class="clear hetong-list">
				<view class="left" v-for="(item,index)  in hetong" :key="index">
					<image :src="item.url" @tap="yulan(item.url)"></image>
				</view>
			</view>
		</view>
		<view class="mokuai" style="margin: 20rpx;padding: 20rpx;">
			<view class="info_title" style="position: relative;">
			    还款明细
			</view>
			<view class="clear shenhe-text" >
				<text class="left">应还金额 </text>
				<text class="right" >{{info.elsecapital}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">应还利息 </text>
				<text class="right" >{{info.investment}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">还款利率 </text>
				<text class="right">{{info.app_rate}}%</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">已还贷款 </text>
				<text class="right">{{info.paymoney}}</text>
			</view>
			<view class="clear shenhe-text" style="position: relative;">
				<text class="left">还款记录 </text>
				<text class="info_more" style="width: 90rpx;right: 0px;" @tap="gorecode()">查看</text>
			</view>
		</view>
		<view class="mokuai" style="margin: 20rpx;padding: 20rpx;"v-if="info.is_finish==-1">
			<view class="info_title" style="position: relative;">
			    逾期明细
			</view>
			<view class="clear shenhe-text" >
				<text class="left">逾期天数 </text>
				<text class="right" >{{info.over_day}}天</text>
			</view>
			
		</view>
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	import {timestampToDate} from '@/static/js/login.js';
	import {timestampToDate1} from '@/static/js/login.js';
	export default {
		data() {
			return {
				isalert:false,//驳回弹出框是否弹出
				current:0,
				iconType: ['success'],
				iskehu:false,
				isyewu:false,
				info:{},
				id:"",
				hetong:[]
			}
		},
		onLoad(option) {
			this.user = getlogin();
			  if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}
			if(this.user.type==1){
				this.iskehu = true;
				this.isyewu = false;
			}else if(this.user.type==2){
				this.isyewu = true;
				this.iskehu = false;
				this.user.member_id=option.member_id;
			}
			if(option.id){
				this.id=option.id;
				this.getinfo();
			}else{
				uni.navigateBack()
			}
			
			
		},
		methods: {
			getinfo(){
				let url=""
				// if(this.user.type==1){
					url="api.php/index/member/getLoanDetail/"
				// }else{
					// url=""
				// }
				uni.request({
				    url: httpPath.filePath+url,
				    method:'POST',
				    header:{'content-type':'application/x-www-form-urlencoded'},
				    data:{member_id:this.user.member_id,id:this.id} ,
				    success: (res) => {
						if(res.data.code=="200"){
							this.info=res.data.result;
							this.info.tongguo=timestampToDate1(res.data.result.checktime3)
							this.info.capital=fmoney(this.info.capital)
							this.info.elsecapital=fmoney(this.info.elsecapital)
							this.info.investment=fmoney(this.info.investment)
							this.info.paymoney=fmoney(this.info.paymoney)
							this.info.addtime=timestampToDate1(this.info.addtime)
							this.info.checktime3=timestampToDate1(this.info.checktime3)
							this.info.endtime=timestampToDate1(this.info.endtime)
							if(this.info.hetong.length!=0){
								 for (let i=0;i<this.info.hetong.length;i++) {
									 this.hetong.push({"url":httpPath.filePath+"/static/upload/image/"+this.info.hetong[i]})
								 }
														
							}
						}
						
				    }
				});
			},
			// 预览图片
	      yulan(img){
		    uni.previewImage({
				  urls: [img],
				  longPressActions: {
					  // itemList: ['发送给朋友', '保存图片', '收藏'],
					  success: function(data) {
						  console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
					  },
					  fail: function(err) {
						  console.log(err.errMsg);
					  }
				  }
		    });
		  }
          ,gorecode(){//点击进入还款记录
			  if(this.user.type==2){
				  uni.navigateTo({
					url:"../kehu/back_recode?id="+this.id+"&member_id="+this.user.member_id
				  })
			  }else{
				  uni.navigateTo({
				  	url:"../kehu/back_recode?id="+this.id
				  })
			  }
			  
		  },backloan(){//点击进入还款页面
			  uni.navigateTo({
			  	url:"../kehu/backloan?id="+this.id
			  })
		  }
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	.bohui-textarea{display: block;margin: 10px;background: #f3f3f3;padding: 5px;height: 300rpx;width: 92%;border-radius: 5px;}
	.info_btn{width: 250rpx;border-radius: 30rpx;height: 60rpx;line-height: 60rpx;font-size: 30rpx;}
	.info_btn:nth-of-type(1){border:  1px solid #1e99ff;color: #1e99ff;}
	.info_btn:nth-of-type(2){background: #1e99ff;color: #FFFFFF;}
	.process{min-height: 100rpx;border-left: 1px solid #1e99ff;margin-left: 20rpx;margin-bottom: 10rpx;padding-left: 30rpx;}
	.info_more{position: absolute;top: 0rpx;right: 10rpx;display: block;width: 150rpx;text-align:center;color: #FFFFFF;font-size: 28rpx;line-height: 40rpx;height: 40rpx;background: #1e99ff;border-radius: 20rpx;}
    .info_title{padding-bottom: 8px;margin-bottom: 8px;}
</style>
